package uba.ing2.subite.services.authorizationrules;

import uba.ing2.subite.domain.Invoice;
import uba.ing2.subite.domain.PaymentCard;
import uba.ing2.subite.services.PaymentAuthorizationResult;
import uba.ing2.subite.services.PaymentCardService;

public class PaymentCardVerificationRule implements PaymentAuthorizationRule {
	private PaymentCardService paymentCardService;

	public PaymentCardVerificationRule(PaymentCardService paymentCardService) {
		this.paymentCardService = paymentCardService;
	}

	@Override
	public PaymentAuthorizationResult apply(Invoice invoice, PaymentCard card) {
		return PaymentAuthorizationResult.createFromCondition(
				paymentCardService.canAcceptPaymentsWith(card), 
				"La tarjeta " + card.identifier() + " no es valida.");
	}
}
